package com.itheima.d9Game;

import java.util.*;

/**
 * 在房间启动的时候，准备54张牌，发牌，牌排序、逻辑
 */

public class Test {
    // 准备牌
    private static List<Card> cards = new ArrayList<>();

    static {
        String[] sizes = {"3", "4", "5", "6", "7", "8", "9", "10", "J", "Q", "K", "A", "2"};
        String[] colors = {"♥", "♣", "♦", "♠"};
        for (int i = 0; i < sizes.length; i++) {
            for (int j = 0; j < colors.length; j++) {
                Card card = new Card();
                card.setSize(sizes[i]);
                card.setColor(colors[j]);
                card.setSizeofCard(i);
                cards.add(card);
            }
        }
        // 大小王
        Card c1 = new Card("", "大🃏",sizes.length+1);
        Card c2 = new Card("", "小🃏",sizes.length);
        Collections.addAll(cards, c1, c2);
        System.out.println("新牌:" + cards);
    }

    public static void main(String[] args) {
        // 洗牌
        Collections.shuffle(cards);
        System.out.println("洗过牌后:" + cards);
        // 发牌 <定义三个玩家，每个玩家都是一个集合容器> 发51张，留3张
        List<Card> player_1 = new ArrayList<>();
        List<Card> player_2 = new ArrayList<>();
        List<Card> player_3 = new ArrayList<>();

        for (int i = 0; i < cards.size()-3; i++) {
            // 轮循 需要立刻反应到取余  每一轮干同一件事情
            if (i < cards.size() - 3) {
                if (i % 3 == 0) {
                    player_1.add(cards.get(i));
                } else if (i % 3 == 1) {
                    player_2.add(cards.get(i));
                } else {
                    player_3.add(cards.get(i));
                }
            }else {

               // player_1.add(cards.get(i)); //地主
            }
        }
        List<Card> cards_last_3 = Test.cards.subList(Test.cards.size() - 3, Test.cards.size());
        player_1.addAll(cards_last_3);
        System.out.println("player1:" + player_1);
        System.out.println("player2:" + player_2);
        System.out.println("player1:" + player_3);
        System.out.println("底牌三张:"+cards_last_3);
        //13. 给玩家排序
        sort_Cards(player_1);
        sort_Cards(player_2);
        sort_Cards(player_3);
        System.out.println("排序:"+player_1);
        System.out.println("排序:"+player_2);
        System.out.println("排序:"+player_3);

    }

    private static void sort_Cards(List<Card> cards) {
        Collections.sort(cards, new Comparator<Card>() {
            @Override
            public int compare(Card o1, Card o2) {
               return o1.getSizeofCard()-o2.getSizeofCard();
            }
        });

    }

}
